﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Demo_SteeringBehaviour
{
    public class Paper: Agent
    {
        #region OBJECT_CONSTRUCTION
        //
        //C001: DEFAULT CONSTRUCTOR
        public Paper(Texture2D texture) : base(texture)
        {
            this.agentType = agent_Type.PAPER;
            Init();
        }

        //C002: OVERLOADED CONSTRUCTOR
        ////public Paper(Texture2D texture, Vector2 position, Vector2 size, agent_Type agentType)
        ////    : base(texture, position, size, agentType)
        ////{
        ////    Init();
        ////}
        
        //
        protected override void Init()
        {
            #region Movement Direction
            //Movement Direction/Angle of obj
            this.angleInRadians = Helper.AngleInRadians_Random();   //Random direction obj moves, in Radians
            this.direction = Helper.Radian2Vector(angleInRadians);  //Direction obj moves, Convert angleInRadians to Vector2

            //Pausing the Agent Controls
            this.pauseCounter = 0.0f;
            this.isPaused = false;

            //Center is based on which direction obj is pointing
            this.center = this.position + Helper.Inverse(this.direction * (this.size / 2));
            this.isAlive = true;
            #endregion

            #region Rotation/Movement Speeds
            //Rotation Speed Controls
            this.rotation_Normal = 0.32f;   //Normal Rotating speed in radians (~18-degrees)
            this.rotation_Max = 0.44f;      //MAX Rotating speed in radians (~25-degrees)

            //Movement Speed Controls
            this.speed_Normal = 0.70f;      //Normal Movement speed of obj
            this.speed_Max = 1.8f;            //MAX Movement speed of obj
            #endregion

            #region Steering_Behaviour
            this.behaviour = null;
            this.behaviourType = behaviour_Type.WANDER;
            #endregion

            #region Wander Behaviour
            this.wDistance = (float)Math.Round(this.size.X * 1.5, 2);
            this.wRadius = (float)Math.Round(this.size.X / 2, 2);
            #endregion

            #region Flee_Behaviour
            this.flee_PanicDistance = (float)Math.Round(this.size.X * 1, 2);
            this.flee_CautionDistance = (float)Math.Round(this.size.X * 1.4, 2);
            this.flee_CapturetDistance = (float)Math.Round(this.size.X / 2, 2);
            this.fleeCounter = 0.0f;
            this.fleeTime = 150f;
            #endregion

            #region Seek_Behaviour
            this.seek_Distance = (float)Math.Round(this.size.X * 3, 2);
            this.seekCounter = 0.0f;
            this.seekTime = 180f;
            #endregion
        }
        //
        #endregion


        #region OVERRIDE_METHODS
        //
        protected override void Spawn()
        {
            AngleInRadians = Helper.AngleInRadians_Random();
            Position = Helper.Position_Random(50, 750, 50, 550);
            this.speed_Current = this.speed_Normal;
        }
        
        //
        public override void Update(GameTime gameTime, List<Agent> agents)
        {
            Update_Behaviour(gameTime, agents);
            Vector2 temp = new Vector2(0.0f);

            if (this.isPaused)
            {
                this.pauseCounter += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
               
                if (this.pauseCounter < PauseTime) 
                { 
                    temp = new Vector2(0.0f);
                }
                else 
                { 
                    this.isPaused = false;  this.pauseCounter = 0.0f;
                    this.isAlive = true;
                    Spawn();
                    temp = new Vector2(this.direction.X * this.speed_Current, this.direction.Y * this.speed_Current);
                }
            }
            else {
                temp = new Vector2(this.direction.X * this.speed_Current, this.direction.Y * this.speed_Current);
            }

            //update Position
            BoundaryCheck(temp);
        }

        //
        public override void Draw(SpriteBatch spriteBatch)
        {
            Vector2 origin = new Vector2(this.size.X / 2, this.size.Y / 2);

            spriteBatch.Draw(this.texture, this.position, null, Color.White, this.angleInRadians + (float)Math.Round(Math.PI / 2, 2), origin, 1, SpriteEffects.None, 0f);
        }
        //
        #endregion
    }//class
}//namespace
